<?php
/**
 * "Book Chapter Content" Model
 *
 * @author hiscaler <hiscaler@gmail.com>
 * @link http://www.yuandot.com/
 * @copyright Copyright &copy; 2009-2010 Yuandot Information Technology CO.,LTD.
 * @license http://doit.yuandot.com/license/
 */

class BookChapterContent extends CActiveRecord {
    /**
     * The followings are the available columns in table '{{books_chapters_contents}}':
     * @var integer $id
     * @var integer $category_id
     * @var string $title
     * @var string $body
     * @var integer $order_pos
     * @var integer $status
     * @var integer $created
     * @var integer $updated
     */

    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{books_chapters_contents}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
        return array(
            array('title, body', 'required'),
            array('category_id, order_pos, status, created, updated', 'numerical', 'integerOnly' => true),
            array('status', 'boolean', 'trueValue' => 1, 'falseValue' => 0),
            array('title', 'length', 'max' => 200),
            array('body', 'safe'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
        return array(
            // 所属章节分类
            'chapterCategory' => array(self::BELONGS_TO, 'BookChapterCategory', 'category_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'Id',
            'category_id' => Yii::t('bookChapterContent', 'category_id'),
            'title' => Yii::t('bookChapterContent', 'title'),
            'body' => Yii::t('bookChapterContent', 'body'),
            'order_pos' => Yii::t('common', 'order_pos'),
            'status' => Yii::t('bookChapterContent', 'status'),
            'created' => Yii::t('bookChapterContent', 'created'),
            'updated' => Yii::t('bookChapterContent', 'updated'),
        );
    }

    public function behaviors() {
        return array(
            'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
                'createAttribute' => 'created',
                'updateAttribute' => 'updated',
            )
        );
    }
}